package com.mmz.gulimall.search.controller;

import com.mmz.gulimall.search.service.MallSearchService;
import com.mmz.gulimall.search.vo.SearchParam;
import com.mmz.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 搜索页面请求及跳转
 *
 * @author mangmangguai
 */
@Controller
public class SearchController {
    @Autowired
    private MallSearchService mallSearchService;

    /**
     * 自动将页面提交过来的所有请求参数封装成指定的对象
     * @param searchParam
     * @param model
     * @return
     */
    @GetMapping("/list.html")
    public String toList(SearchParam searchParam, Model model) {
        //1、根据页面传递过来的查询参数，去es中检索商品
        SearchResult result = mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }
}
